﻿Imports System.Runtime.Serialization

Namespace Model

    <DataContract()> _
    Public Class LiveProgram
        Implements ICloneable

        <DataMember()> _
        Private _Id As Integer
        ''' <summary>
        ''' Live ID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Id() As Integer
            Get
                Return _Id
            End Get
            Set(ByVal value As Integer)
                _Id = value
            End Set
        End Property

        <DataMember()> _
        Private _CasterName As String
        ''' <summary>
        ''' 放送者名
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>未取得のときはnull(Nothing)</remarks>
        Public Property CasterName() As String
            Get
                Return _CasterName
            End Get
            Set(ByVal value As String)
                _CasterName = value
            End Set
        End Property

        <DataMember()> _
        Private _CasterId As Integer?
        ''' <summary>
        ''' 放送者ID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>未取得のときはnull(Nothing)</remarks>
        Public Property CasterId() As Integer?
            Get
                Return _CasterId
            End Get
            Set(ByVal value As Integer?)
                _CasterId = value
            End Set
        End Property

        <DataMember()> _
        Private _Title As String = ""
        ''' <summary>
        ''' タイトル
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        <DataMember()> _
        Private _Content As String = ""
        ''' <summary>
        ''' 紹介文（全文を未取得時は省略された紹介文）
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Content() As String
            Get
                Return If(HasFullContent, _Content, _ShortContent)
            End Get
            Set(ByVal value As String)
                _Content = value
                HasFullContent = True
            End Set
        End Property

        <DataMember()> _
        Private _ShortContent As String = ""
        ''' <summary>
        ''' 省略された紹介文
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ShortContent() As String
            Get
                Return _ShortContent
            End Get
            Set(ByVal value As String)
                _ShortContent = value
            End Set
        End Property

        <DataMember()> _
        Private _VisitorCount As Integer
        ''' <summary>
        ''' 来場者数
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property VisitorCount() As Integer
            Get
                Return _VisitorCount
            End Get
            Set(ByVal value As Integer)
                _VisitorCount = value
            End Set
        End Property

        <DataMember()> _
        Private _CommentCount As Integer
        ''' <summary>
        ''' コメント数
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CommentCount() As Integer
            Get
                Return _CommentCount
            End Get
            Set(ByVal value As Integer)
                _CommentCount = value
            End Set
        End Property

        <DataMember()> _
        Private _StartDateTime As DateTime
        ''' <summary>
        ''' 放送開始時間
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property StartDateTime() As DateTime
            Get
                Return _StartDateTime
            End Get
            Set(ByVal value As DateTime)
                _StartDateTime = value
            End Set
        End Property

        <DataMember()> _
        Private _Station As New Station
        ''' <summary>
        ''' 放送局
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Station() As Station
            Get
                Return _Station
            End Get
        End Property

        <DataMember()> _
        Private _OfficialTag As String = ""
        ''' <summary>
        ''' タグ
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property OfficialTag() As String
            Get
                Return _OfficialTag
            End Get
            Set(ByVal value As String)
                _OfficialTag = value
            End Set
        End Property

#Region "Flags"
        ''' <summary>
        ''' 限定放送
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsMemberOnly() As Boolean
            Get
                Return (_Flags And LiveProgramFlags.MemberOnly) = LiveProgramFlags.MemberOnly
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    _Flags = _Flags Or LiveProgramFlags.MemberOnly
                Else
                    _Flags = _Flags And Not LiveProgramFlags.MemberOnly
                End If
            End Set
        End Property

        ''' <summary>
        ''' 顔出し
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsFace() As Boolean
            Get
                Return (_Flags And LiveProgramFlags.Face) = LiveProgramFlags.Face
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    _Flags = _Flags Or LiveProgramFlags.Face
                Else
                    _Flags = _Flags And Not LiveProgramFlags.Face
                End If
            End Set
        End Property

        ''' <summary>
        ''' 凸待ち
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsTotsu() As Boolean
            Get
                Return (_Flags And LiveProgramFlags.Totsu) = LiveProgramFlags.Totsu
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    _Flags = _Flags Or LiveProgramFlags.Totsu
                Else
                    _Flags = _Flags And Not LiveProgramFlags.Totsu
                End If
            End Set
        End Property

        ''' <summary>
        ''' 予約放送
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsReserved() As Boolean
            Get
                Return (_Flags And LiveProgramFlags.Reserved) = LiveProgramFlags.Reserved
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    _Flags = _Flags Or LiveProgramFlags.Reserved
                Else
                    _Flags = _Flags And Not LiveProgramFlags.Reserved
                End If
            End Set
        End Property

#End Region

        <DataMember()> _
        Private _IsOnAir As Boolean
        ''' <summary>
        ''' 放送中であるか
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsOnAir() As Boolean
            Get
                Return _IsOnAir
            End Get
            Set(ByVal value As Boolean)
                _IsOnAir = value
            End Set
        End Property

        <DataMember()> _
        Private _CrawlingDateTime As DateTime
        ''' <summary>
        ''' 情報取得日時
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CrawlingDateTime() As DateTime
            Get
                Return _CrawlingDateTime
            End Get
            Set(ByVal value As DateTime)
                _CrawlingDateTime = value
            End Set
        End Property

        <DataMember()> _
        Private _HasFullContent As Boolean
        ''' <summary>
        ''' 紹介文の内容が全文であるか
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property HasFullContent() As Boolean
            Get
                Return _HasFullContent
            End Get
            Set(ByVal value As Boolean)
                _HasFullContent = value
            End Set
        End Property

        <DataMember()> _
        Private _Flags As LiveProgramFlags
        ''' <summary>
        ''' 放送の属性
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Flags() As LiveProgramFlags
            Get
                Return _Flags
            End Get
            Set(ByVal value As LiveProgramFlags)
                _Flags = value
            End Set
        End Property

        <DataMember()> _
        Private _IsAlerted As Boolean
        Public Property IsAlerted() As Boolean
            Get
                Return _IsAlerted
            End Get
            Set(ByVal value As Boolean)
                _IsAlerted = value
            End Set
        End Property

        <DataMember()> _
        Private _AlertReason As AlertReason
        Public Property AlertReason() As AlertReason
            Get
                Return _AlertReason
            End Get
            Set(ByVal value As AlertReason)
                _AlertReason = value
            End Set
        End Property

        Public ReadOnly Property Uri() As Uri
            Get
                Return New Uri(String.Format(System.Globalization.CultureInfo.InvariantCulture, My.Settings.LiveProgramsUriFormat, Id))
            End Get
        End Property

        Public Shared ReadOnly Property LiveProgramsUriFormat() As String
            Get
                Return My.Settings.LiveProgramsUriFormat
            End Get
        End Property


        Public Function Clone() As Object Implements System.ICloneable.Clone

            Dim program = New LiveProgram With { _
                .Id = Me.Id, _
                .CasterName = Me.CasterName, _
                .CasterId = Me.CasterId, _
                .Title = Me.Title, _
                .ShortContent = Me.ShortContent, _
                .VisitorCount = Me.VisitorCount, _
                .CommentCount = Me.CommentCount, _
                .StartDateTime = Me.StartDateTime, _
                .OfficialTag = Me.OfficialTag, _
                .IsOnAir = Me.IsOnAir, _
                .CrawlingDateTime = Me.CrawlingDateTime, _
                .HasFullContent = Me.HasFullContent, _
                .Flags = Me.Flags}

            If Me.HasFullContent Then
                program.Content = Me.Content
            End If

            Dim station = DirectCast(Me.Station.Clone, Station)

            With program.Station
                .Id = station.Id
                .Name = station.Name
                .UpdateDateTime = station.UpdateDateTime
                .Rating = station.Rating
                .IsAlertTarget = station.IsAlertTarget
                .Level = station.Level
                .MemberCount = station.Level
                .IconUri = station.IconUri
            End With

            For Each i In Me.Station.PluginGuids
                program.Station.PluginGuids.Add(i)
            Next


            Return program
        End Function

    End Class

End Namespace
